
//创建不同对象
var $ = function(){
	return new Base();//每次调用都创建
}
function Base() {
	//创建一个数组，来保存获取的节点和节点数组
	this.elements = [];

	//获取id节点
	this.getId = function(id) {
		this.elements.push(document.getElementById(id));
		return this;
	};

	//获取name节点数组
	this.getName = function(name) {

		var names = document.getElementsByName(name);
		for(var i = 0; i < names.length; i++) {
			this.elements.push(targs[i]);
		}
		return this;

	}

	//获取元素节点
	this.getTagName = function(tagName) {
		//可能获取多个
		var tags = document.getElementsByTagName(tagName);
		for(var i = 0; i < tags.length; i++) {
			this.elements.push(tags[i]);
		}

		return this;
	};
}

//原型封装设置css属性
Base.prototype.css = function(attr, value) {
	for(var i = 0; i < this.elements.length; i++) {
		this.elements[i].style[attr] = value; //设置属性值
	}

	return this;

}
//html属性
Base.prototype.html = function (str) {
	for (var i = 0; i < this.elements.length; i ++) {
		this.elements[i].innerHTML = str;
	}
	return this;
}
//点击属性
Base.prototype.click = function (fn) {
	for (var i = 0; i < this.elements.length; i ++) {
		this.elements[i].onclick = fn;
	}
	return this;
}


//调用
window.onload = function() {
	//var base = new Base();//如果用同一个对象，后面的属性覆盖前面的
	$().getId('box').css('color', 'red').css('backgroundColor', 'black');
	//alert(base.getTagName('p').elements.length);
	$().getTagName('p').css('color', 'green').html('标题').click(function () {
		alert('点击');
	}).css('backgroundColor', 'pink');
}